﻿using System;
using System.Collections.Generic;

namespace CoreRay
{
    /// <summary>
    /// Stores indices to vertex in a buffer.
    /// </summary>
    public class IndexBuffer
    {
        private List<int> indexBuffer;

        /// <summary>
        /// Initializes a new instance of the <see cref="IndexBuffer"/> class.
        /// </summary>
        public IndexBuffer()
        {
            // Init private list
            this.indexBuffer = new List<int>();
        }

        /// <summary>
        /// Gets the count of indices in the buffer.
        /// </summary>
        /// <value>Count of indices.</value>
        public int Count
        {
            get
            {
                return this.indexBuffer.Count;
            }
        }

        /// <summary>
        /// Gets the index of the vertex at the specified offset.
        /// </summary>
        /// <param name="offset">The offset in the buffer.</param>
        /// <returns>Index to a vertex.</returns>
        public int GetVertexIndex(int offset)
        {
            return this.indexBuffer[offset];
        }

        /// <summary>
        /// Writes the specified index to the index buffer.
        /// </summary>
        /// <param name="index">The index to write.</param>
        public void Write(int index)
        {
            this.indexBuffer.Add(index);
        }
    }
}
